
package sales.managedbean;

import company.entity.Company;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import sales.entity.LineItem;
import sales.entity.SalesOrderEntity;


@ManagedBean
@ViewScoped
public class DisplayPurchaseOrderManagedBean implements Serializable{
   private SalesOrderEntity purchaseOrder;
   private Company customer;
   private Collection<LineItem> lineItemList;
   private String path;
    /** Creates a new instance of DisplaySalesOrderManagedBean */
    public DisplayPurchaseOrderManagedBean() {
       path ="";
    }
    
    public void initView(PhaseEvent event) {
        if (purchaseOrder == null) { 
            purchaseOrder = (SalesOrderEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("purchaseOrder");
            path =(String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("lastURL");
        }
            setLineItemList(purchaseOrder.getSalesOrderLineItems());
            setCustomer(purchaseOrder.getCustomer());
    }
    public void reDirect() throws IOException{
       
 
        FacesContext.getCurrentInstance().getExternalContext().redirect(path);
    }
   
    public SalesOrderEntity getPurchaseOrder() {
        return purchaseOrder;
    }

    public void setPurchaseOrder(SalesOrderEntity salesOrder) {
        this.purchaseOrder = salesOrder;
    }

    public Company getCustomer() {
        return customer;
    }

    public void setCustomer(Company customer) {
        this.customer = customer;
    }

    public Collection<LineItem> getLineItemList() {
        return lineItemList;
    }

    public void setLineItemList(Collection<LineItem> lineItemList) {
        this.lineItemList = lineItemList;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
